//
//  TransactCellModel.m
//  KD
//
//  Created by Hubery on 15/8/17.
//  Copyright (c) 2015年 centling. All rights reserved.
//

#import "OddNumberModel.h"
/**
 @property(nonatomic,copy)NSString * oddNumber;//单号
 @property(nonatomic,assign) NSString* oddNumberState;//订单状态
 
 @property(nonatomic,copy)NSString *price;//已付价格
 @property(nonatomic,copy)NSString *overduePrice;//逾期金额
 
 
 @property(nonatomic,copy)NSString *sum;//总数
 
 @property(nonatomic,copy)NSString *finishDate;// 完成日期
 @property(nonatomic,copy)NSString *distillDate;//提货日期
 */

/**
 {
 "price": "456456",
 "oddNumber": "OPLGFDHR66",
 "sum": "12",
 "oddNumberState": 4
 },
 */
/**
 [
 {
 "price": "12313",
 "distillDate": "12-3-13",
 "oddNumber": "ASFSFGAF123124",
 "sum": "12",
 "oddNumberState": "0"
 },
 {
 "price": "456456",
 "oddNumber": "OPLGFDHR66",
 "sum": "12",
 "finishDate": "12-3-13",
 "oddNumberState": "4"
 },
 {
 "oddNumber": "KJHLG66888",
 "oddNumberState": "3"
 },
 {
 "price": "34345",
 "oddNumber": "UYTIYUO7766",
 "distillDate": "12-3-13",
 "sum": "345345",
 "oddNumberState": "2"
 },
 {
 "overduePrice": "34534",
 "oddNumber": "AGFDSGD524",
 "sum": "12",
 "oddNumberState": "1"
 }
 ]
 */
@implementation OddNumberModel
+(instancetype)oddNumberWithDict:(NSDictionary *)dict
{
        return [[self alloc]initWithDict:dict];
}

-(instancetype)initWithDict:(NSDictionary *)dict
{
    if(self = [super init])
    {
        int state = [dict[@"oddNumberState"] intValue];
        switch (state) {
            case 0://未付款
                /**
                 {
                 "price": "12313",
                 "distillDate": "12-3-13",
                 "oddNumber": "ASFSFGAF123124",
                 "sum": "12",
                 "oddNumberState": "0"
                 },
                 */
                self.price = dict[@"price"];
                self.oddNumberState = [self stateWithNumber:state];
                self.sum = dict[@"sum"];
                self.oddNumber = dict[@"oddNumber"];
                self.distillDate = dict[@"distillDate"];
                break;
            case 1://逾期
                /**
                 {
                 "overduePrice": "34534",
                 "oddNumber": "AGFDSGD524",
                 "sum": "12",
                 "oddNumberState": "1"
                 }
                 */
                self.overduePrice = dict[@"overduePrice"];
                self.oddNumberState = [self stateWithNumber:state];
                self.sum = dict[@"sum"];
                self.oddNumber = dict[@"oddNumber"];
                
                break;
            case 2://进行中
                /**
                 {
                 "price": "34345",
                 "oddNumber": "UYTIYUO7766",
                 "distillDate": "12-3-13",
                 "sum": "345345",
                 "oddNumberState": "2"
                 },
                 */
                self.price = dict[@"price"];
                self.oddNumberState = [self stateWithNumber:state];
                self.sum = dict[@"sum"];
                self.oddNumber = dict[@"oddNumber"];
                self.distillDate = dict[@"distillDate"];
                break;
            case 3://未通关
                /**
                 "oddNumber": "KJHLG66888",
                 "oddNumberState": "3"
                 */
                self.oddNumberState = [self stateWithNumber:state];
                self.oddNumber = dict[@"oddNumber"];
                break;
            case 4://完成
                /**
                 {
                 "price": "456456",
                 "oddNumber": "OPLGFDHR66",
                 "sum": "12",
                 "finishDate": "12-3-13",
                 "oddNumberState": "4"
                 },
                 */
                self.price = dict[@"price"];
                self.oddNumberState = [self stateWithNumber:state];
                self.sum = dict[@"sum"];
                self.oddNumber = dict[@"oddNumber"];
                self.finishDate = dict[@"finishDate"];
                break;
                
            default://数据错误
                self.oddNumberState = [self stateWithNumber:state];
                break;
        }

    }
    return self;
}


//根据订单状态返回文字状态
-(NSString *)stateWithNumber:(int)num
{
    /**
     单号状态
     0:未付款
     1:逾期
     2:进行中
     3:未通关
     4:完成
     */
    
    switch (num) {
        case 0:
            return @"未付款";
            break;
        case 1:
            return @"逾期";
            break;
        case 2:
            return @"进行中";
            break;
        case 3:
            return @"未通关";
            break;
        case 4:
            return @"完成";
            break;
            
        default:
            return @"error";
            break;
    }
}

-(NSString *)description
{
    return[NSString stringWithFormat:@"<%@: %p> {oddNumber: %@, \n oddNumberState:%@, \n price: %@,  \n overduePrice:%@,  \n sum:%@,  \n finishDate:%@,  \n distillDate:%@}",self.class,self,self.oddNumber,self.oddNumberState,self.price,self.overduePrice,self.sum,self.finishDate,self.distillDate];
}

@end
